home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
HPAVC
/
HPAVC CD-ROM.iso
/
MCASM.RAR
/
MC_ASM.EXE
/
WROX_ASM
/
CH9
/
UNERASE
/
GET.ASM
next >
Wrap
Assembly Source File
|
1994-05-22
|
4KB
|
193 lines
MODEL SMALL
.386
PUBLIC get_boot
PUBLIC get_sector
PUBLIC set_sector
PUBLIC get_root
.CODE
i25startsec dd ?
i25countsec dw ?
i25off dw ?
i25seg dw ?
get_boot PROC C FAR
ARG drive:byte
LOCAL addr1:word
USES cx,dx,ds
mov ah,48h ; Allocate memory for boot sector
mov bx,32
int 21h
jc @@get_boot_err
mov addr1,ax
mov ds,ax
xor bx,bx
mov al,drive
mov cx,1
xor dx,dx
int 25h ; Read boot sector
pop dx
jnc @@get_boot_010
; Disk is larger than 32 Mbytes.
mov word ptr i25startsec,0
mov word ptr i25startsec+2,0
mov i25countsec,1
mov i25off,0
mov i25seg,ds
mov al,drive
mov cx,0ffffh
push cs
pop ds
lea bx,i25startsec
int 25h ; Read boot sector
pop dx
jc @@get_boot_err
@@get_boot_010: xor ax,ax
mov bx,addr1
ret
@@get_boot_err: mov ax,-1
ret
get_boot ENDP
get_sector PROC C FAR
ARG drive:byte,sector:dword,addr:dword,count:word
USES bx,cx,dx,di,si,ds
mov ds,word ptr addr+2
mov bx,word ptr addr
mov dx,word ptr sector
mov cx,count
mov al,drive
int 25h
pop dx
jnc @@get_sec_010
; Disk is larger than 32 Mbytes.
mov ax,word ptr sector
mov word ptr i25startsec,ax
mov ax,word ptr sector+2
mov word ptr i25startsec+2,ax
mov ax,count
mov i25countsec,ax
mov ax,word ptr addr
mov i25off,ax
mov i25seg,ds
mov al,drive
mov cx,0ffffh
push cs
pop ds
lea bx,i25startsec
int 25h
pop dx
jc @@get_boot_err
@@get_sec_010: xor ax,ax
ret
@@get_sec_err: mov ax,-1
ret
get_sector ENDP
set_sector PROC C FAR
ARG drive:byte,sector:dword,addr:dword,count:word
USES bx,cx,dx,di,si,ds
mov ds,word ptr addr+2
mov bx,word ptr addr
mov dx,word ptr sector
mov cx,count
mov al,drive
int 26h
pop dx
jnc @@set_sec_010
; Disk is larger than 32 Mbytes.
mov ax,word ptr sector
mov word ptr i25startsec,ax
mov ax,word ptr sector+2
mov word ptr i25startsec+2,ax
mov ax,count
mov i25countsec,ax
mov ax,word ptr addr
mov i25off,ax
mov i25seg,ds
mov al,drive
mov cx,0ffffh
push cs
pop ds
lea bx,i25startsec
int 26h
pop dx
jc @@get_boot_err
@@set_sec_010: xor ax,ax
ret
@@set_sec_err: mov ax,-1
ret
set_sector ENDP
get_root PROC C FAR
ARG drive:byte,addr:dword
LOCAL addr1:word,startsector:word
USES cx,dx,ds
mov ax,word ptr addr+2
mov ds,ax
mov bx,word ptr addr
add bx,0eh
mov ax,word ptr ds:[bx] ; Sectors before FAT
add bx,2
mov cl,byte ptr ds:[bx] ; Number of the FAT
dec cl
add bx,6
mov dx,word ptr ds:[bx] ; Number of sectors in one FAT
shl dx,cl ; Number of sectors in both FAT
add ax,dx ; Number of sectors before root
mov startsector,ax
sub bx,5
mov dx,word ptr ds:[bx] ; Maximum root directory entries
mov cl,4
shr dx,cl ; Root directory in sectors
inc dx ; dx*32/512+1
mov bx,dx
mov cl,5
shl bx,cl ; Root directory in bytes
mov ah,48h ; Allocate memory
int 21h
jnc @@get_root_010
jmp @@get_root_err
@@get_root_010: mov addr1,ax
mov ds,ax
mov cx,dx
push cx
mov dx,startsector
mov al,drive
xor bx,bx
int 25h ; Read root
pop dx
pop cx
jnc @@get_root_020
; Disk is larger than 32 Mbytes.
mov ax,startsector
mov word ptr i25startsec,ax
mov word ptr i25startsec+2,0
mov i25countsec,cx
mov i25off,0
mov i25seg,ds
mov al,drive
mov cx,0ffffh
push cs
pop ds
lea bx,i25startsec
int 25h
pop dx
jc @@get_root_err
@@get_root_020: xor ax,ax
mov bx,addr1
ret
@@get_root_err: mov ax,-1
ret
get_root ENDP
END